﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;

namespace EntityFramework.ServiceLayer
{
    public class OlaConfiguration : ConfigurationSection
    {
        private const string SECTION_NAME = "ola.config";

        public static OlaConfiguration LoadConfiguration()
        {
           return ConfigurationManager.GetSection(SECTION_NAME) as OlaConfiguration;
        }

        [ConfigurationProperty("ConnectionString", IsRequired = true)]
        public string ConnectionString
        {
            get
            {
                return (string)this["ConnectionString"];
            }
            set
            {
                this["ConnectionString"] = value;
            }
        }

        [ConfigurationProperty("EntityFrameworkConnectionString", IsRequired = true)]
        public string EntityFrameworkConnectionString
        {
            get
            {
                return (string) this["EntityFrameworkConnectionString"];
            }
            set
            {
                this["EntityFrameworkConnectionString"] = value;
            }
        }

        [ConfigurationProperty("IsolationLevel", IsRequired = true)]
        public IsolationLevel IsolationLevel
        {
            get
            {
                return (IsolationLevel)this["IsolationLevel"];
            }
            set
            {
                this["IsolationLevel"] = value.ToString();
            }
        }

        [ConfigurationProperty("MaxAttachmentSizeInBytes", DefaultValue = 3145728)]
        public int MaxAttachmentSizeInBytes 
        {
            get
            {
                return (int)this["MaxAttachmentSizeInBytes"];
            }
            set
            {
                this["MaxAttachmentSizeInBytes"] = value;
            }
        }

        [ConfigurationProperty("MaxTotalAttachmentSizePerOrderInBytes", DefaultValue = 8388608)]
        public int MaxTotalAttachmentSizePerOrderInBytes
        {
            get
            {
                return (int)this["MaxTotalAttachmentSizePerOrderInBytes"];
            }
            set
            {
                this["MaxTotalAttachmentSizePerOrderInBytes"] = value;
            }
        }

      

        [ConfigurationProperty("DevelopmentEmailAddress", DefaultValue = "")]
        public string DevelopmentEmailAddress
        {
            get
            {
                return (string)this["DevelopmentEmailAddress"];
            }
            set
            {
                this["DevelopmentEmailAddress"] = value;
            }
        }

        [ConfigurationProperty("MaxNumberAttachmentPerOrder", DefaultValue = 15)]
        public int MaxNumberAttachmentPerOrder
        {
            get
            {
                return (int)this["MaxNumberAttachmentPerOrder"];
            }
            set
            {
                this["MaxNumberAttachmentPerOrder"] = value;
            }
        }

        [ConfigurationProperty("ExchangeRateCacheTTLInHours", DefaultValue = 24.0)]
        public double ExchangeRateCacheTTLInHours
        {
            get
            {
                return (double)this["ExchangeRateCacheTTLInHours"];
            }
            set
            {
                this["ExchangeRateCacheTTLInHours"] = value;
            }
        }

        [ConfigurationProperty("SessionTokenCacheTTLInMinutes", DefaultValue = 60)]
        public int SessionTokenCacheTTLInMinutes
        {
            get
            {
                return (int)this["SessionTokenCacheTTLInMinutes"];
            }
            set
            {
                this["SessionTokenCacheTTLInMinutes"] = value;
            }
        }

        [ConfigurationProperty("FromEmailAddress", IsRequired = true)]
        public string FromEmailAddress
        {
            get
            {
                return (string)this["FromEmailAddress"];
            }
            set
            {
                this["FromEmailAddress"] = value;
            }
        }

        [ConfigurationProperty("OpenOrderLink", IsRequired = true)]
        public string OpenOrderLink
        {
            get
            {
                return (string)this["OpenOrderLink"];
            }
            set
            {
                this["OpenOrderLink"] = value;
            }
        }

        [ConfigurationProperty("EmailTemplateDirectory", IsRequired = true)]
        public string EmailTemplateDirectory
        {
            get
            {
                return (string)this["EmailTemplateDirectory"];
            }
            set
            {
                this["EmailTemplateDirectory"] = value;
            }
        }

        [ConfigurationProperty("SmtpHost", IsRequired = false)]
        public string SmtpHost
        {
            get
            {
                return (string)this["SmtpHost"];
            }
            set
            {
                this["SmtpHost"] = value;
            }
        }

        [ConfigurationProperty("SmtpUserName", IsRequired = false)]
        public string SmtpUserName
        {
            get
            {
                return (string)this["SmtpUserName"];
            }
            set
            {
                this["SmtpUserName"] = value;
            }
        }

        [ConfigurationProperty("SmtpPassword", IsRequired = false)]
        public string SmtpPassword
        {
            get
            {
                return (string)this["SmtpPassword"];
            }
            set
            {
                this["SmtpPassword"] = value;
            }
        }

        [ConfigurationProperty("SmtpDomain", IsRequired = false)]
        public string SmtpDomain
        {
            get
            {
                return (string)this["SmtpDomain"];
            }
            set
            {
                this["SmtpDomain"] = value;
            }
        }

        [ConfigurationProperty("GemBoxLicense", IsRequired = true)]
        public string GemBoxLicense
        {
            get
            {
                return (string)this["GemBoxLicense"];
            }
            set
            {
                this["GemBoxLicense"] = value;
            }
        }

        [ConfigurationProperty("ExportMaxOrders", IsRequired = true)]
        public int ExportMaxOrders
        {
            get
            {
                return (int)this["ExportMaxOrders"];
            }
            set
            {
                this["ExportMaxOrders"] = value;
            }
        }

    }

}
